package com.lz.football.module.playerCenter
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.constants.ClubConst;
	import com.liangzhong.model.goods.vo.PlayerStarVo;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;

	/**
	 *球员卡 
	 * @author Administrator
	 * 
	 */	
	public class PlayerCard extends Sprite implements IComponent
	{
		private var _skin:MovieClip;
		public function PlayerCard()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			_skin = Reflection.createInstance("com.liangzhong.ui.playCard");
			this.addChild(_skin);
		}
		/**
		 *设置球员数据(球星转化成球员，在球员中心使用) 
		 * @param star
		 * 
		 */		
		public function setData(star :PlayerVo):void
		{
			_skin.gotoAndStop(star.color);
			_skin.mc.txtLv.text 			= "" + star.level;
			_skin.mc.txtName.text 			= "" + star.starVo.name;
			_skin.mc.ability.text 			= "" + star.ability;
			
			
			_skin.mc.txtattack.text 		= "" + star.attack;
			_skin.mc.txtdefence.text 		= "" + star.defence;
			_skin.mc.txtsteal.text 		= "" + star.steal;
			_skin.mc.txtpower.text 		= "" + star.power;
			_skin.mc.txtspeed.text 		= "" + star.speed;
			_skin.mc.txtcontrol.text 		= "" + star.control;
			
			//属性加成
			if(star.attackAdd > 0)
				_skin.mc.txtattackadd.text 		= "+" + star.attackAdd;
			else
				_skin.mc.txtattackadd.text 		= "";
			if(star.defenceAdd > 0)
				_skin.mc.txtdefenceadd.text 		= "+" + star.defenceAdd;
			else 
				_skin.mc.txtdefenceadd.text 		=  "";
			if(star.stealAdd >0)
				_skin.mc.txtstealadd.text 		= "+" + star.stealAdd;
			else
				_skin.mc.txtstealadd.text 		= "";
			if(star.powerAdd > 0)
				_skin.mc.txtpoweradd.text 		= "+" + star.powerAdd;
			else 
				_skin.mc.txtpoweradd.text 		= "";
			if(star.speedAdd > 0)
				_skin.mc.txtspeedadd.text 		= "+" + star.speedAdd;
			else 
				_skin.mc.txtspeedadd.text 		= "";
			if(star.controlAdd > 0)
				_skin.mc.txtcontroladd.text 		= "+" + star.controlAdd;
			else 
				_skin.mc.txtcontroladd.text 		= "";
			
			var frameIndex :int = 1;
			var maxValue   :int = ClubConst.colorToPro(star.color);
			/*frameIndex = star.attack / maxValue * 11;
			_skin.mc.attackProMc.gotoAndStop(frameIndex);
			frameIndex = star.defence / maxValue * 11;
			_skin.mc.defenceProMc.gotoAndStop(frameIndex);
			frameIndex = star.steal / maxValue * 11;
			_skin.mc.stealProMc.gotoAndStop(frameIndex);
			frameIndex = star.power / maxValue * 11;
			_skin.mc.powerProMc.gotoAndStop(frameIndex);
			frameIndex = star.speed / maxValue * 11;
			_skin.mc.speedProMc.gotoAndStop(frameIndex);
			frameIndex = star.control / maxValue * 11;
			_skin.mc.controlProMc.gotoAndStop(frameIndex);*/
			var showW :Number = 0;
			showW = star.attack / maxValue * 70;
			_skin.mc.attackProMc.pmc.width = showW;
			showW = star.defence / maxValue * 70;
			_skin.mc.defenceProMc.pmc.width = showW;
			showW = star.steal / maxValue * 70;
			_skin.mc.stealProMc.pmc.width = showW;
			showW = star.power / maxValue * 70;
			_skin.mc.powerProMc.pmc.width = showW;
			showW = star.speed / maxValue * 70;
			_skin.mc.speedProMc.pmc.width = showW;
			showW = star.control / maxValue * 70;
			_skin.mc.controlProMc.pmc.width = showW;
			
			_skin.mc.txtPlace.text = "" + star.place_String;
			//_skin.mc.txtAbiliy.text =  "" + star.ability;
			//大头像
			var bigImgBg :MovieClip = _skin.mc.bigImgBg;
			var bigBData :BitmapData = star.starVo.bigBitmapData;
			var bigBitMap :Bitmap = new Bitmap(bigBData);
			DisplayObjectUtil.removeAllChildren(bigImgBg.pContainer);
			if(bigImgBg)
			{
				bigImgBg.pContainer.addChild(bigBitMap);
			}
		}
		
		
		
		/**
		 *设置球星数据（读表的球星数据） 
		 * @param $vo
		 * 
		 */
		public function setStartDate($vo:PlayerStarVo):void
		{
			var star:PlayerStarVo = $vo;
			_skin.gotoAndStop(star.color);
			_skin.mc.txtLv.text 			= "" + star.level;
			_skin.mc.txtName.text 			= "" + star.name;
			_skin.mc.ability.text 			= "" + star.ability;
			
			
			_skin.mc.txtattack.text 		= "" + star.attack;
			_skin.mc.txtdefence.text 		= "" + star.defence;
			_skin.mc.txtsteal.text 		= "" + star.steal;
			_skin.mc.txtpower.text 		= "" + star.power;
			_skin.mc.txtspeed.text 		= "" + star.speed;
			_skin.mc.txtcontrol.text 		= "" + star.control;
			
			var frameIndex :int = 1;
			var maxValue   :int = ClubConst.colorToPro(star.color);
			var showW :Number = 0;
			showW = star.attack / maxValue * 70;
			_skin.mc.attackProMc.pmc.width = showW;
			showW = star.defence / maxValue * 70;
			_skin.mc.defenceProMc.pmc.width = showW;
			showW = star.steal / maxValue * 70;
			_skin.mc.stealProMc.pmc.width = showW;
			showW = star.power / maxValue * 70;
			_skin.mc.powerProMc.pmc.width = showW;
			showW = star.speed / maxValue * 70;
			_skin.mc.speedProMc.pmc.width = showW;
			showW = star.control / maxValue * 70;
			_skin.mc.controlProMc.pmc.width = showW;
			
			_skin.mc.txtPlace.text = "" + star.placeName;
			//_skin.mc.txtAbiliy.text =  "" + star.ability;
			//大头像
			var bigImgBg :MovieClip = _skin.mc.bigImgBg;
			var bigBData :BitmapData = star.bigBitmapData;
			var bigBitMap :Bitmap = new Bitmap(bigBData);
			DisplayObjectUtil.removeAllChildren(bigImgBg.pContainer);
			if(bigImgBg)
			{
				bigImgBg.pContainer.addChild(bigBitMap);
			}
		}
		public function addEvtListener():void
		{
		}
		
		public function removeEvtListener():void
		{
		}
		
		public function destroyView():void
		{
			if(this.parent)this.parent.removeChild(this);
		}
	}
}